package com.yanqu.road.logic.pb;

import com.yanqu.road.entity.decoration.DecorationSimple;
import com.yanqu.road.entity.decoration.MammonCongratulateTime;
import com.yanqu.road.entity.decoration.MammonRecord;
import com.yanqu.road.entity.player.UserBaseInfo;
import com.yanqu.road.entity.player.UserDecoration;
import com.yanqu.road.entity.decoration.UserMammon;
import com.yanqu.road.entity.rank.cross.CrossUserDecoration;
import com.yanqu.road.pb.decoration.DecorationProto;
import com.yanqu.road.pb.player.PlayerProto;

import java.util.List;
import java.util.Map;

public class DecorationPb {
    public static DecorationProto.DecorationTempMsg.Builder parseDecorationTempMsg(UserDecoration userDecoration){
        if(null == userDecoration){
            return null;
        }
        DecorationProto.DecorationTempMsg.Builder msg = DecorationProto.DecorationTempMsg.newBuilder();
        msg.setDecorationId(userDecoration.getDecorationId());
        msg.setEndTime(userDecoration.getEndTime());
        msg.setModifyTime(userDecoration.getModifyTime());
        return msg;
    }

    public static DecorationProto.DecorationListMsg.Builder parseDecorationListMsg(List<UserDecoration> userDecorationList){
        DecorationProto.DecorationListMsg.Builder listMsg = DecorationProto.DecorationListMsg.newBuilder();
        if(null != userDecorationList){
            for(UserDecoration userDecoration : userDecorationList) {
                DecorationProto.DecorationTempMsg.Builder msg = parseDecorationTempMsg(userDecoration);
                if(null != msg){
                    listMsg.addDecorationList(msg);
                }
            }
        }
        return listMsg;
    }

    public static DecorationProto.MammonTempMsg.Builder parseMammonTempMsg(UserDecoration userDecoration, UserBaseInfo userBaseInfo){
        if(null == userDecoration || null == userBaseInfo){
            return null;
        }
        DecorationProto.MammonTempMsg.Builder msg = DecorationProto.MammonTempMsg.newBuilder();
        msg.setDecorationId(userDecoration.getDecorationId());
        msg.setEndTime(userDecoration.getEndTime());
        msg.setUserId(userDecoration.getUserId());
        PlayerProto.PlayerBaseTempMsg.Builder baseMsg = PlayerBasePb.parsePlayerBaseTempMsg(userBaseInfo);
        if(null != baseMsg) {
            msg.setPlayerBaseData(baseMsg);
        }
        return msg;
    }

    public static DecorationProto.MammonTempMsg.Builder parseMammonTempMsg(CrossUserDecoration crossUserDecoration){
        if(null == crossUserDecoration){
            return null;
        }
        DecorationProto.MammonTempMsg.Builder msg = DecorationProto.MammonTempMsg.newBuilder();
        msg.setDecorationId(crossUserDecoration.getDecorationId());
        msg.setEndTime(crossUserDecoration.getEndTime());
        msg.setUserId(crossUserDecoration.getUserId());
        PlayerProto.PlayerBaseTempMsg.Builder baseMsg = PlayerBasePb.parsePlayerBaseTempMsg(crossUserDecoration.getUserBaseInfo());
        if(null != baseMsg) {
            msg.setPlayerBaseData(baseMsg);
        }
        return msg;
    }

    public static DecorationProto.MammonListMsg.Builder parseMammonListMsg(List<CrossUserDecoration> crossUserDecorationList){
        DecorationProto.MammonListMsg.Builder listMsg = DecorationProto.MammonListMsg.newBuilder();
        if(null != crossUserDecorationList){
            for(CrossUserDecoration crossUserDecoration : crossUserDecorationList) {
                DecorationProto.MammonTempMsg.Builder msg = parseMammonTempMsg(crossUserDecoration);
                if(null != msg){
                    listMsg.addMammonList(msg);
                }
            }
        }
        return listMsg;
    }

    public static DecorationProto.MammonDataMsg.Builder parseMammonDataMsg(UserMammon userMammon){
        if(null == userMammon){
            return null;
        }
        DecorationProto.MammonDataMsg.Builder msg = DecorationProto.MammonDataMsg.newBuilder();
        msg.setWorshipTime(userMammon.getWorshipTime());
        msg.setMammonSkillId(userMammon.getMammonSkillId());
        msg.setEffectTimes(userMammon.getEffectTimes());
        return msg;
    }

    public static DecorationProto.MammonRecordTempMsg.Builder parseMammonRecordTempMsg(MammonRecord mammonRecord){
        if(null == mammonRecord){
            return null;
        }
        DecorationProto.MammonRecordTempMsg.Builder msg = DecorationProto.MammonRecordTempMsg.newBuilder();
        msg.setRecordUid(mammonRecord.getRecordUid());
        msg.setUserId(mammonRecord.getUserId());
        PlayerProto.PlayerBaseTempMsg.Builder baseMsg = PlayerBasePb.parsePlayerBaseTempMsg(mammonRecord.getUserBaseInfo());
        msg.setPlayerBaseData(baseMsg);
        msg.setRecordTime(mammonRecord.getRecordTime());
        msg.setMammonIndex(mammonRecord.getMammonIndex());
        return msg;
    }

    public static MammonRecord parseMammonRecord(int decorationId, DecorationProto.MammonRecordTempMsg recordTempMsg){
        if(null == recordTempMsg){
            return null;
        }
        MammonRecord mammonRecord = new MammonRecord();
        mammonRecord.setRecordUid(recordTempMsg.getRecordUid());
        mammonRecord.setType(decorationId);
        mammonRecord.setUserId(recordTempMsg.getUserId());
        mammonRecord.setRecordTime(recordTempMsg.getRecordTime());
        mammonRecord.setUserBaseInfo(PlayerBasePb.parseToUserBaseInfo(recordTempMsg.getPlayerBaseData()));
        return mammonRecord;
    }

    public static DecorationProto.MammonRecordListMsg.Builder parseMammonRecordListMsg(List<MammonRecord> mammonRecordList){
        DecorationProto.MammonRecordListMsg.Builder listMsg = DecorationProto.MammonRecordListMsg.newBuilder();
        if(null != mammonRecordList){
            for(MammonRecord mammonRecord : mammonRecordList){
                DecorationProto.MammonRecordTempMsg.Builder msg = parseMammonRecordTempMsg(mammonRecord);
                if(null != msg){
                    listMsg.addDataList(msg);
                }
            }
        }
        return listMsg;
    }

    public static DecorationProto.MammonCongratulateDataTempMsg.Builder parseMammonCongratulateDataTempMsg(MammonCongratulateTime mammonCongratulateTime){
        if(null == mammonCongratulateTime){
            return null;
        }
        DecorationProto.MammonCongratulateDataTempMsg.Builder msg = DecorationProto.MammonCongratulateDataTempMsg.newBuilder();
        msg.setType(mammonCongratulateTime.getType());
        msg.setRecordTime(mammonCongratulateTime.getRecordTime());
        msg.setCongratulateTime(mammonCongratulateTime.getCongratulateTime());
        return msg;
    }

    public static DecorationProto.MammonCongratulateDataListMsg.Builder parseMammonCongratulateDataListMsg(List<MammonCongratulateTime> congratulateTimeList){
        DecorationProto.MammonCongratulateDataListMsg.Builder listMsg = DecorationProto.MammonCongratulateDataListMsg.newBuilder();
        if(null != congratulateTimeList){
            for(MammonCongratulateTime mammonCongratulateTime : congratulateTimeList){
                DecorationProto.MammonCongratulateDataTempMsg.Builder msg = parseMammonCongratulateDataTempMsg(mammonCongratulateTime);
                if(null != msg) {
                    listMsg.addDataList(msg);
                }
            }
        }
        return listMsg;
    }

    public static DecorationProto.DecorationSimpleTempMsg.Builder parseDecorationSimpleTempMsg(DecorationSimple data){
        if(null == data){
            return null;
        }
        DecorationProto.DecorationSimpleTempMsg.Builder msg = DecorationProto.DecorationSimpleTempMsg.newBuilder();
        msg.setDecorationId(data.getDecorationId());
        msg.setEndTime(data.getEndTime());
        return msg;
    }

    public static DecorationSimple parseDecorationSimple(DecorationProto.DecorationSimpleTempMsg tempMsg){
        if(null == tempMsg){
            return null;
        }
        DecorationSimple data = new DecorationSimple();
        data.setDecorationId(tempMsg.getDecorationId());
        data.setEndTime(tempMsg.getEndTime());
        return data;
    }
}
